package cn.buyclss.backend.controller.wechat;

import cn.buyclss.backend.entity.dto.Token;
import cn.buyclss.backend.entity.support.RespCode;
import cn.buyclss.backend.entity.support.RespResult;
import cn.buyclss.backend.entity.vo.WechatLoginVO;
import cn.buyclss.backend.service.wechat.WxAppletService;
import org.apache.shiro.authz.annotation.RequiresAuthentication;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * @author: Cecurio
 * @create: 2019-02-20 17:30
 **/
//@RestController
//@RequestMapping("/wechat")
public class LoginController {
    @Autowired
    private WxAppletService wxAppletService;

//    @RequestMapping("/login")
    public Token login(@RequestBody WechatLoginVO loginVO) {
        Token res = new Token();
        System.out.println(loginVO);
        res = wxAppletService.wxUserLogin(loginVO.getCode());
        return res;
    }


    /**
     * 需要认证的测试接口  需要 @RequiresAuthentication 注解，则调用此接口需要 header 中携带自定义登陆态 authorization
     */
    @RequiresAuthentication
//    @PostMapping("/sayHello")
    public ResponseEntity sayHello() {
        Map<String, String> result = new HashMap<>();
        result.put("words", "hello World");
        return new ResponseEntity<>(result, HttpStatus.OK);
    }
}
